{$CLEO .qa}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "DRNKQA"

// By ArtemQa146

const
    man_1 = 31@
    progress = 25@
    coords_x = 24@
    coords_y = 23@
    coords_z = 22@
    angle_1 = 21@
end

0087: coords_x = 0@ // (float)
0087: coords_y = 1@ // (float)
0087: coords_z = 2@ // (float)
0087: angle_1 = 3@ // (float)


if
    0E4D: random_percent 50
then
else
    repeat
    wait 0
    until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 150.0
    0A93: terminate_this_custom_script
end


        repeat
        wait 0
        04ED: load_animation  "PedEventsMod"
        until 04EE:   animation "PedEventsMod" loaded
        
        0209: 1@ = random_int_in_ranges 1 5
        if 1@ == 1
        then 2@ = 15
        end
        if 1@ == 2
        then 2@ = 44
        end
        if 1@ == 3
        then 2@ = 48
        end
        if 1@ == 4
        then 2@ = 60
        end

        model.Load(2@)
        if
            not model.Available(2@)
        then
            repeat
            wait 0
            model.Load(2@)
            until model.Available(2@)
        end
        038B: load_requested_models

        009A: man_1 = create_actor_pedtype 21 model 2@ at coords_x coords_y coords_z
        0173: set_actor man_1 Z_angle_to angle_1
        0E24: fix_char man_1 ground 1 brightness 1 and_fade_in 0
        0812: AS_actor man_1 perform_animation "drnkq2" IFP "PedEventsMod" framedelta 8.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB

        model.Destroy(2@)
        timera = 0

        wait 300

        repeat
        wait 0
        if
            056D:   actor man_1 defined
        then

            080E: get_actor man_1 ped_event_to 1@
            if or
                0118:   actor man_1 dead
                not locate_char_distance_to_char $player_actor char man_1 radius 150.0
                not $ACTIVE_INTERIOR == 0
                not is_char_script_controlled man_1
            then
                break
            end

            
            if
                051A:   actor man_1 damaged_by_actor $PLAYER_ACTOR
            then
                if or
                    progress == 1
                    progress == 0
                then
                    progress = 146
                end
            end
            
            if
                progress == 146
            then
                0812: AS_actor man_1 perform_animation "drnkq4" IFP "PedEventsMod" framedelta 8.0 loopA 0 lockX 0 lockY 0 lockF 1 time -1  // versionB
                progress = 147
                timerb = 0
            end


            if
                0EE4: locate_char_distance_to_char $PLAYER_ACTOR char man_1 radius 10.0
            then
                if and
                    progress == 0
                    timerb > 10000
                then
                    timerb = 0
                    progress = 1
                end
            else
                if
                    progress == 0
                then
                    timerb = 0
                end
            end
            
            if
                progress == 1
            then
                if
                    0611:   actor man_1 performing_animation "drnkq2"
                then
                    0613: 1@ = actor man_1 animation "drnkq2" time
                    if
                        1@ > 0.95
                    then
                        0615: define_AS_pack_begin 1@
                        0812: AS_actor -1 perform_animation "drnkq1" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 1 lockY 1 lockF 0 time -1  // versionB
                        0812: AS_actor -1 perform_animation "drnkq5" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
                        0616: define_AS_pack_end 1@
                        0618: assign_actor man_1 to_AS_pack 1@
                        061B: remove_references_to_AS_pack 1@
                        progress = 2
                        timerb = 0
                    end
                end
            end
            
            if or
                progress == 2
                progress == 147
            then
                if
                    TIMERB > 50000
                then
                    0812: AS_actor man_1 perform_animation "drnkq3" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 1 time -1  // versionB
                    progress = 3
                end
            end
            
            if
                progress == 3
            then
                if
                    0611:   actor man_1 performing_animation "drnkq3"
                then
                    0613: 1@ = actor man_1 animation "drnkq3" time
                    if
                        1@ > 0.95
                    then
                        break
                    end
                end
            end


        else
            break
        end

        until not player.Defined(0)

        if 056D:   actor man_1 defined
        then 01C2: remove_references_to_actor man_1 // Like turning an actor into a random pedestrian
        end
        04EF: release_animation "PedEventsMod"

        repeat
        wait 0
        until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 100.0

0A93: terminate_this_custom_script
